/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import bean.NoRefrigerado;
import bean.Refrigerado;
import Servicio.ServicioFacturacion;
import bean.Contenedor;
import bean.Servicio;
import java.util.ArrayList;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import main.Main;

/**
 *
 * @author Karina
 */
public class PanelContenedores1 extends javax.swing.JPanel {

    private static int idCont;
    
    public int getId(){
        return idCont;
    }
    
    private int variable;
    
    ContenedorTm miContenedorTM = new ContenedorTm();
    ServiciosTm miServicioTM= new ServiciosTm();
      
    public void actualizaTabla() {
        miContenedorTM.conts=main.Main.service.queryAllContenedor();
        //miContenedorTM.conts=main.Main.service.queryAllObjectsContenedor();
        miContenedorTM.fireTableChanged(null);
    }
    
    public void actualizaTabla2(){
        miServicioTM.servs=main.Main.service.queryAllServxCont(idCont);
        miServicioTM.fireTableChanged(null);
        TableColumn column = null;
        column = TablaServiciosxContenedor.getColumnModel().getColumn(1);
        column.setPreferredWidth(200);
        
        float total = 0f;
        for (int i=0; i< miServicioTM.servs.size(); i++){
            total += miServicioTM.servs.get(i).getPreciobase();
        }
        txtTotal.setText("" + total);
        
    }
    
    private void groupButton( ) { //Bloquear los campos segun los radio buttons

        ButtonGroup bg1 = new ButtonGroup( );

        bg1.add(rbtnRefrigerado);
        bg1.add(rbtnNoRefrigerado);   

    }
    
    class ServiciosTm extends AbstractTableModel{

        ArrayList<Servicio> servs= main.Main.service.queryAllServxCont(idCont);
        String titulos2[]={"IDSERVICIO","DESCRIPCION","PRECIO BASE","UNIDAD DE COBRO"};
        
        @Override
        public int getRowCount() {
            return servs.size();
        }

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            String res=null;
            Servicio serv= servs.get(rowIndex);
                
             switch(columnIndex){
                case 0: res = "" + serv.getId();break;
                case 1:res="" + serv.getDescripcion();break;
                case 2:res=""+serv.getPreciobase();break;
                case 3:res=""+serv.getUnidadcobro();break;
             }


            return res;
        }
        
        @Override
        public String getColumnName(int col){//COLOCA LOS TITULOS DESEADOS
            return titulos2[col];
        }
       
   }
    
    class ContenedorTm extends AbstractTableModel{

        ArrayList<Contenedor> conts = main.Main.service.queryAllContenedor();
        String titulos[]={"CODIGO","PESO NETO","PESO BRUTO","VOLUMEN","DESCRIPCION MERCADERIA","TARA","TIPOCONTENEDOR","MOTOR","TEMPERATURA","TIPO CONTENIDO","ESTADO"};
        
        
        @Override
        public int getRowCount() {
            return conts.size();
        }

        @Override
        public int getColumnCount() {
            return 11 ;
        }

        @Override
       public Object getValueAt(int rowIndex, int columnIndex) {            
            String res=null;
            Contenedor cont= conts.get(rowIndex);
                
             switch(columnIndex){
                 
                case 0:res = "" + cont.getId();break;
                case 1:res = "" + cont.getPeso_neto();break;
                case 2:res = "" + cont.getPeso_bruto();break;
                case 3:res="" + cont.getVolumen();break;
                case 4:res="" + cont.getDescripcionMerc();break;
                case 5:res="" + cont.getTara(); break;
                case 6:res=cont.getTipoContenedor();break;
                case 7: if (cont instanceof Refrigerado){
                    res="" + ((Refrigerado)cont).getMotor();break;
                }else {res="-"; break;}
                case 8:if (cont instanceof Refrigerado){
                    res="" + ((Refrigerado)cont).getTemperatura();break;
                }else {res="-"; break;}
                case 9:if (cont instanceof NoRefrigerado){
                    res="" + ((NoRefrigerado)cont).getTipoContenido();break;
                }else {res="-"; break;}
                case 10: if (cont instanceof NoRefrigerado){
                    res="" + ((NoRefrigerado)cont).getEstado();break;
                }else {res="-"; break;}
             }


         return res;
        }
        
        @Override
        public String getColumnName(int col){//COLOCA LOS TITULOS DESEADOS
            return titulos[col];
        }
        
    }
    
    
    
    
    public PanelContenedores1() {
        initComponents();
        TablaContenedores.setModel(miContenedorTM);
        TablaServiciosxContenedor.setModel(miServicioTM);
        groupButton();
        actualizaTabla();
        actualizaTabla2();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txtPesoBruto = new javax.swing.JTextField();
        txtPesoNeto = new javax.swing.JTextField();
        txtVolumen = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtDescMercaderia = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtTipoContenedor = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtTara = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        rbtnRefrigerado = new javax.swing.JRadioButton();
        rbtnNoRefrigerado = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txtMotor = new javax.swing.JTextField();
        txtTemperatura = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtEstado = new javax.swing.JTextField();
        txtTipoContenido = new javax.swing.JTextField();
        btnAdd = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        ButtonAddServicios = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TablaContenedores = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TablaServiciosxContenedor = new javax.swing.JTable();
        jLabel12 = new javax.swing.JLabel();
        txtTotal = new javax.swing.JTextField();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Contenedores"));

        jLabel1.setText("ID Contenedor");

        txtId.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdActionPerformed(evt);
            }
        });

        jLabel2.setText("Peso Bruto");

        jLabel3.setText("Peso Neto");

        jLabel4.setText("Volumen");

        txtPesoNeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesoNetoActionPerformed(evt);
            }
        });

        jLabel5.setText("Descripcion");

        jLabel6.setText("Tipo Contenedor");

        jLabel11.setText("Tara");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtId)
                    .addComponent(txtPesoBruto)
                    .addComponent(txtPesoNeto)
                    .addComponent(txtVolumen, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE))
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtTipoContenedor, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addComponent(txtDescMercaderia)
                    .addComponent(txtTara))
                .addGap(37, 37, 37))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(txtId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtPesoBruto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(txtDescMercaderia))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtPesoNeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(txtTipoContenedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtVolumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(txtTara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Tipo Contenedor"));

        rbtnRefrigerado.setText("Refrigerado");

        rbtnNoRefrigerado.setText("No Refrigerado");
        rbtnNoRefrigerado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbtnNoRefrigeradoActionPerformed(evt);
            }
        });

        jLabel7.setText("Motor");

        jLabel8.setText("Temperatura");

        txtMotor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMotorActionPerformed(evt);
            }
        });

        txtTemperatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTemperaturaActionPerformed(evt);
            }
        });

        jLabel9.setText("Estado");

        jLabel10.setText("Tipo Contenido");

        txtEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEstadoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addGap(49, 49, 49)
                                .addComponent(txtMotor, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(txtTemperatura)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addGap(43, 43, 43)
                                .addComponent(txtEstado, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTipoContenido)))
                        .addContainerGap())
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(rbtnRefrigerado)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(rbtnNoRefrigerado)
                        .addGap(103, 103, 103))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtnRefrigerado)
                    .addComponent(rbtnNoRefrigerado))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtMotor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtTemperatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(txtTipoContenido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnAdd.setText("Agregar");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnCancel.setText("Limpiar");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnDelete.setText("Eliminar");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnEdit.setText("Editar");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        ButtonAddServicios.setText("Agregar Servicio");
        ButtonAddServicios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonAddServiciosActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Contenedores Tramarsa"));

        TablaContenedores.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablaContenedores.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TablaContenedoresMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(TablaContenedores);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Servicios del Contenedor"));

        TablaServiciosxContenedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(TablaServiciosxContenedor);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel12.setText("Total:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(250, 250, 250)
                        .addComponent(btnAdd)
                        .addGap(39, 39, 39)
                        .addComponent(btnCancel)
                        .addGap(43, 43, 43)
                        .addComponent(btnDelete)
                        .addGap(40, 40, 40)
                        .addComponent(btnEdit)
                        .addGap(49, 49, 49)
                        .addComponent(ButtonAddServicios))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel12)
                .addGap(18, 18, 18)
                .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(57, 57, 57))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd)
                    .addComponent(btnCancel)
                    .addComponent(btnDelete)
                    .addComponent(btnEdit)
                    .addComponent(ButtonAddServicios))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void rbtnRefrigeradoActionPerformed(java.awt.event.ActionEvent evt) {                                                
        txtMotor.setEditable(true);
        txtTemperatura.setEditable(true);
        txtEstado.setText("");
        txtEstado.setEditable(false);
        txtTipoContenido.setText("");
        txtTipoContenido.setEditable(false);
        variable=0;
    }
    
    
    
    private void txtIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdActionPerformed

    private void txtPesoNetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesoNetoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPesoNetoActionPerformed

    private void txtMotorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMotorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtMotorActionPerformed

    private void txtTemperaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTemperaturaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtTemperaturaActionPerformed

    private void txtEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEstadoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtEstadoActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        int rowSel = TablaContenedores.getSelectedRow();
        int idContenedor = Integer.parseInt(TablaContenedores.getValueAt(rowSel, 0).toString());
        Main.service.eliminaContenedor(idContenedor);
        actualizaTabla();
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        if(variable==0){
            Refrigerado refrig = new Refrigerado();

            refrig.setId(Integer.parseInt(txtId.getText()));
            refrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            refrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            refrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            refrig.setDescripcionMerc(txtDescMercaderia.getText());
            refrig.setTara(Float.parseFloat(txtTara.getText()));
            refrig.setTipoContenedor(txtTipoContenedor.getText());
            refrig.setMotor(txtMotor.getText());
            
            refrig.setTemperatura(Float.parseFloat(txtTemperatura.getText()));

            Main.service.agregaContenedor(refrig);
            //Main.service.sacoDocumento(id).addContenedor(refrig);

        }else{ //Agrego un contenedor no Refrigerado
            NoRefrigerado noRefrig = new NoRefrigerado();
            noRefrig.setId(Integer.parseInt(txtId.getText()));
            noRefrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            noRefrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            noRefrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            noRefrig.setDescripcionMerc(txtDescMercaderia.getText());
            noRefrig.setTara(Float.parseFloat(txtTara.getText()));
            noRefrig.setTipoContenedor(txtTipoContenedor.getText());
            noRefrig.setEstado(txtEstado.getText());
            
            noRefrig.setTipoContenido(txtTipoContenido.getText());
            
            Main.service.agregaContenedor(noRefrig);
        }
        int idCont=Integer.parseInt(txtId.getText());
        int idDoc=Main.principal.doc.getPanelDocumentos1().getId();
        
        
        Main.principal.cont.setVisible(false);
        Main.service.agregaDocXcont(idDoc,idCont);        
        Main.principal.doc.getPanelDocumentos1().ActualizaTCont();
        actualizaTabla();
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        txtId.setText(null);
        txtPesoNeto.setText(null);
        txtPesoBruto.setText(null);
        txtVolumen.setText(null);
        txtEstado.setText(null);
        txtDescMercaderia.setText(null);
        txtTemperatura.setText(null);
        txtTipoContenido.setText(null);
        txtMotor.setText(null);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void rbtnNoRefrigeradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbtnNoRefrigeradoActionPerformed
        txtMotor.setEditable(false);
        txtMotor.setText("");
        txtTemperatura.setText("");
        txtTemperatura.setEditable(false);
        txtEstado.setEditable(true);
        txtTipoContenido.setEditable(true);
        variable=1;
    }//GEN-LAST:event_rbtnNoRefrigeradoActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
       if(variable==0){
            Refrigerado refrig = new Refrigerado();

            refrig.setId(Integer.parseInt(txtId.getText()));
            refrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            refrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            refrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            refrig.setDescripcionMerc(txtDescMercaderia.getText());
            refrig.setMotor(txtMotor.getText());
            refrig.setTemperatura(Integer.parseInt(txtTemperatura.getText()));

            Main.service.editaContenedor(refrig);
            actualizaTabla();

        }else{ //Agrego un contenedor no Refrigerado
            NoRefrigerado noRefrig = new NoRefrigerado();
            noRefrig.setId(Integer.parseInt(txtId.getText()));
            noRefrig.setPeso_neto(Float.parseFloat(txtPesoNeto.getText()));
            noRefrig.setPeso_bruto(Float.parseFloat(txtPesoBruto.getText()));
            noRefrig.setVolumen(Float.parseFloat(txtVolumen.getText()));
            noRefrig.setDescripcionMerc(txtDescMercaderia.getText());
            noRefrig.setEstado(txtEstado.getText());
            noRefrig.setTipoContenido(txtTipoContenido.getText());

            Main.service.editaContenedor(noRefrig);
            actualizaTabla();
        }
    }//GEN-LAST:event_btnEditActionPerformed

    private void TablaContenedoresMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TablaContenedoresMouseClicked
        int rowSel = TablaContenedores.getSelectedRow();
        int idContenedor = Integer.parseInt(TablaContenedores.getValueAt(rowSel, 0).toString());
        Contenedor c=main.Main.service.queryByContenedor(idContenedor);

        
        txtId.setText(""+c.getId());
        txtPesoNeto.setText(""+c.getPeso_neto());
        txtPesoBruto.setText(""+c.getPeso_bruto());
        txtVolumen.setText(""+c.getVolumen());
        txtDescMercaderia.setText(c.getDescripcionMerc());
        txtTara.setText(""+c.getTara());
        txtTipoContenedor.setText(""+c.getTipoContenedor());
        
        if (c instanceof Refrigerado){
            txtMotor.setText(""+((Refrigerado)c).getMotor());
            txtTemperatura.setText(""+((Refrigerado)c).getTemperatura());
            txtMotor.setEditable(true);
            txtTemperatura.setEditable(true);
            txtEstado.setEditable(false);
            txtEstado.setText(null);
            txtTipoContenido.setEditable(false);
            txtTipoContenido.setText(null);
            variable=0;
        }else {
          if (c instanceof NoRefrigerado){
            txtEstado.setText(""+((NoRefrigerado)c).getEstado());
            txtTipoContenido.setText(""+((NoRefrigerado)c).getTipoContenido());
            txtMotor.setEditable(false);
            txtMotor.setText(null);
            txtTemperatura.setEditable(false);
            txtTemperatura.setText(null);
            txtEstado.setEditable(true);
            txtTipoContenido.setEditable(true);
            variable=1;
          }
        }
        idCont=Integer.parseInt(txtId.getText());
        actualizaTabla2();
    }//GEN-LAST:event_TablaContenedoresMouseClicked

    private void ButtonAddServiciosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonAddServiciosActionPerformed
        InternalFrameServicio serv = new InternalFrameServicio();
        Main.principal.getEscritorio().add(serv);
        serv.toFront();
        serv.setVisible(true);
    }//GEN-LAST:event_ButtonAddServiciosActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonAddServicios;
    private javax.swing.JTable TablaContenedores;
    private javax.swing.JTable TablaServiciosxContenedor;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton rbtnNoRefrigerado;
    private javax.swing.JRadioButton rbtnRefrigerado;
    private javax.swing.JTextField txtDescMercaderia;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtId;
    private javax.swing.JTextField txtMotor;
    private javax.swing.JTextField txtPesoBruto;
    private javax.swing.JTextField txtPesoNeto;
    private javax.swing.JTextField txtTara;
    private javax.swing.JTextField txtTemperatura;
    private javax.swing.JTextField txtTipoContenedor;
    private javax.swing.JTextField txtTipoContenido;
    private javax.swing.JTextField txtTotal;
    private javax.swing.JTextField txtVolumen;
    // End of variables declaration//GEN-END:variables
}
